package br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.leftmenu.user;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;
import br.edu.ufcg.lsd.wbis.ui.client.ui.loggedin.admin.allusers.AllUsersTab;
import br.edu.ufcg.lsd.wbis.ui.client.ui.management.InfoManager;

import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.TabPanel;
import com.gwtext.client.widgets.menu.BaseItem;
import com.gwtext.client.widgets.menu.event.BaseItemListenerAdapter;

/**
 * @author Renato Miceli
 */
public class UserManagerListener extends BaseItemListenerAdapter {

	private final TabPanel centerPanel;

	private final InfoManager<UserInfo> loggedManager;

	public UserManagerListener(TabPanel centerPanel, InfoManager<UserInfo> loggedManager) {
		this.centerPanel = centerPanel;
		this.loggedManager = loggedManager;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onClick(BaseItem item, EventObject e) {
		for (Component c : this.centerPanel.getItems()) {
			if (c.getItemId().equals(AllUsersTab.ITEM_ID)) {
				this.centerPanel.activate(c.getId());
				return;
			}
		}
		AllUsersTab allUsersTab = new AllUsersTab(centerPanel, loggedManager);
		this.centerPanel.add(allUsersTab);
		this.centerPanel.activate(allUsersTab.getId());
	}

}
